package cn.exrick.xboot.common.advice;

import cn.exrick.xboot.common.enums.ExceptionEnum;
import cn.exrick.xboot.common.exception.jiuqiException;
import cn.exrick.xboot.common.vo.ExceptionResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class BasicExceptionHandler {
    /**
     * njp
     * 处理自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(jiuqiException.class)
    public ResponseEntity<ExceptionResult> handleException(jiuqiException e) {
        log.info("统一错误处理");
        //System.out.println("统一错误处理");
        ExceptionResult er=   new ExceptionResult(e.getExceptionEnum());
        System.out.println("ExceptionResult"+er.getMessage());
        System.out.println("ExceptionResult"+er.getStatus());
        // return ResponseEntity.status(e.getExceptionEnum().value()).body(new ExceptionResult(e.getExceptionEnum()));
        //return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());

        return ResponseEntity.status(e.getExceptionEnum().value()).body(er);
    }
}
